﻿using AutoMapper;
using HSGD.Model.Dtos.HSGD_Family;
using HSGD.Model.Models.HSGD_Family;
using System.Globalization;

namespace HSGD.Extensions.Profiles.HSGDFamily {
    public class HSGDFamilyProfiles : Profile {
        public HSGDFamilyProfiles() {
            CreateMap<ChildDto, Child>()
             .ForMember(
                    dest => dest.date_of_birth,
                    opt => opt.MapFrom(src => string.IsNullOrEmpty(src.dob) ? new DateTime?() : DateTime.ParseExact(src.dob, "MM/dd/yyyy", CultureInfo.InvariantCulture))
                );
            CreateMap<Child, ChildDto>()
             .ForMember(
                    dest => dest.dob,
                   opt => opt.MapFrom(src => src.date_of_birth.HasValue ? src.date_of_birth.Value.ToShortDateString() : "")
                );

            //.ForMember(a => a.date_of_birth?.ToString("MM/dd/yyyy"), o => o.MapFrom(d => d.dob));
            //.ForMember(a => a.date_of_birth.Value.ToString("MM/dd/yyyy"), o => o.MapFrom(d => d.dob));
            //.ForMember(a => a.date_of_birth, o => o.MapFrom(d => d.date_of_birth?.ToString("MM/dd/yyyy")));
        }
    }
}
